<?php

namespace app\api\model\user;

use app\logic\model\user\UserCouponLogicModel;

class UserCouponApiModel extends UserCouponLogicModel
{

    function getApiList($param,$field='*',$page = 1,$limit =1){
        $query=$this
            ->where(function ($q) use ($param){
                if(check_request($param,'user_coupon_id_api_model.status')){
                    $q->where("status",$param['status']);
                }
                if(check_request($param,'user_id')){
                    $q->where("user_id",$param['user_id']);
                }
            })->field($field)->withJoin(['coupon'])->visible([
                'coupon'=>['title','enough_price','price']
            ]);
        $list = $query->page($page,$limit)->select();
        $count = $query->count();
        return [$list,$count];
    }
}